﻿
#include "HttpHandles.h"
#include "../../iocp/IOCP/fileio.h"
#include "../../utils/jsoncpp/value.h"
#include "../../utils/jsoncpp/reader.h"
CHttpHandles::CHttpHandles()
{
}

CHttpHandles::~CHttpHandles()
{
}

#define HTTP_VERSION  "HTTP/1.1 "
#define HTTPERROR_RESPONSE_204 "204 No Content\r\n"
#define HTTPERROR_RESPONSE_200 "200 OK\r\n"


void __stdcall CHttpHandles::GetToken(PHTTPINFO pHttpInfo)
{
    char strContentLength[64] = {0};
    std::string strToken;
    std::string strResponse;

    if (0 == _stricmp(pHttpInfo->strModle, "post"))
    {
        //只有Post 請求，才能拿到 token
        //BoxApi_GetUserToken(strToken);
    }

    //try
    //{
    //    nlohmann::json json = {
    //        {"code", strToken.length() ? 1 : 0},
    //        {"msg", strToken.length() ? "succeed" : "user is not login"},
    //        {"data", strToken}
    //    };
    //    strResponse = json.dump();
    //}CatchNlohmannJson();

    fileio_write(pHttpInfo->hHttp, HTTP_VERSION HTTPERROR_RESPONSE_200,
                 strlen(HTTP_VERSION) + strlen(HTTPERROR_RESPONSE_200));
    sprintf(strContentLength, "content-length: %d\r\n\r\n", strResponse.length());
    fileio_write(pHttpInfo->hHttp, strContentLength, strlen(strContentLength));
    fileio_write(pHttpInfo->hHttp, strResponse.c_str(), strResponse.length());
}
